CSharpTest.Net
SetList<T> Constructor(IComparer<T>)
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > SetList<T> Class > SetList<T> Constructor : SetList<T> Constructor(IComparer<T>)

comparer

Glossary Item Box

Constructs a SetList

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal comparer As IComparer(Of T) _
)
C# 
public SetList<T>( 
   IComparer<T> comparer
)

Parameters

comparer

Example

Library/Library.Test/TestSetList.cs

C#Copy Code
IList list = new SetList<string>(StringComparer.Ordinal);
Assert.AreEqual(0, list.Count);
list.Add("a");
Assert.AreEqual(1, list.Count);
list.Add("B");
Assert.AreEqual(2, list.Count);

Assert.AreEqual("B", list[0]);
Assert.AreEqual("a", list[1]);

Assert.IsTrue(list.Contains("a"));
Assert.IsFalse(list.Contains("A"));
Assert.IsFalse(list.Contains("b"));
Assert.IsTrue(list.Contains("B"));

Assert.AreEqual(0, list.IndexOf("B"));
Assert.AreEqual(1, list.IndexOf("a"));

list = new SetList<string>((IEnumerable<string>)list, StringComparer.OrdinalIgnoreCase);
Assert.AreEqual(2, list.Count);
Assert.AreEqual("a", list[0]);
Assert.AreEqual("B", list[1]);

Assert.IsTrue(list.Contains("a"));
Assert.IsTrue(list.Contains("A"));
Assert.IsTrue(list.Contains("b"));
Assert.IsTrue(list.Contains("B"));

Assert.IsFalse(list.Contains(5));
Assert.IsTrue(list.IndexOf(5) < 0);

Assert.IsFalse(list.IsFixedSize);
list.Remove("b");
Assert.IsFalse(list.Contains("b"));
Assert.IsFalse(list.Contains("B"));

list = (IList)((ICloneable)list).Clone();
Assert.AreEqual(typeof(SetList<string>), list.GetType());
Assert.IsTrue(list.Contains("a"));
Assert.IsFalse(list.Contains("b"));
Assert.AreEqual(0, list.IndexOf("a"));
VB.NETCopy Code
Dim list As IList = New SetList(Of String)(StringComparer.Ordinal)
Assert.AreEqual(0, list.Count)
list.Add("a")
Assert.AreEqual(1, list.Count)
list.Add("B")
Assert.AreEqual(2, list.Count)

Assert.AreEqual("B", list(0))
Assert.AreEqual("a", list(1))

Assert.IsTrue(list.Contains("a"))
Assert.IsFalse(list.Contains("A"))
Assert.IsFalse(list.Contains("b"))
Assert.IsTrue(list.Contains("B"))

Assert.AreEqual(0, list.IndexOf("B"))
Assert.AreEqual(1, list.IndexOf("a"))

list = New SetList(Of String)(DirectCast(list, IEnumerable(Of String)), StringComparer.OrdinalIgnoreCase)
Assert.AreEqual(2, list.Count)
Assert.AreEqual("a", list(0))
Assert.AreEqual("B", list(1))

Assert.IsTrue(list.Contains("a"))
Assert.IsTrue(list.Contains("A"))
Assert.IsTrue(list.Contains("b"))
Assert.IsTrue(list.Contains("B"))

Assert.IsFalse(list.Contains(5))
Assert.IsTrue(list.IndexOf(5) < 0)

Assert.IsFalse(list.IsFixedSize)
list.Remove("b")
Assert.IsFalse(list.Contains("b"))
Assert.IsFalse(list.Contains("B"))

list = DirectCast((DirectCast(list, ICloneable)).Clone(), IList)
Assert.AreEqual(GetType(SetList(Of String)), list.[GetType]())
Assert.IsTrue(list.Contains("a"))
Assert.IsFalse(list.Contains("b"))
Assert.AreEqual(0, list.IndexOf("a"))

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys